#!/usr/bin/env bash


# ----------------------------------------------------------------------
# Filename	:  banner
# Version	:  1.0
# Date		:  2022/02/22
# Author	:  Lz
# Email		:  liuzuo@kylinos.com.cn 
# History	:     
#            	   Version 1.0, 2022/02/22
# Function	:  ssh 登录banner 信息
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------


# 测试主题
Title_Env_LTFLIB="安全加固(接入类) - ssh登录Banner信息"


## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB(){
	if [ "Z${Banner_Access_SSRFlag}" == "Z" ];then
		OutputRet_LTFLIB "${ERROR}"	
		TestRetParse_LTFLIB "未定义变量 Banner_Access_SSRFlag"
	elif [ "Z${Banner_Access_SSRFlag}" != "ZTrue" -a "Z${Banner_Access_SSRFlag}" != "ZFalse" ];then
		OutputRet_LTFLIB "${ERROR}"	
		TestRetParse_LTFLIB "Banner_Access_SSRFlag 无效的参数: ${Banner_Access_SSRFlag}"
	fi

        return $TPASS
}


## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB(){
        return $TPASS
}


## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB(){
        testcase_1

        return $TPASS
}

# 文件内容测试
testcase_1(){
        local flag_str="^Banner"
        local false_str="${flag_str}"
        local true_str=""
        # 查看文件中配置
        local file_conf="/etc/ssh/sshd_config"

        local cmd="sudo cat ${file_conf}"
	eval ${cmd} | grep "${flag_str}"
	if [ "Z${Banner_Access_SSRFlag}" == "ZTrue" ];then
        	true_str="${flag_str} +none"

		eval ${cmd} | grep -Eq "${true_str}"
		CommRetParse_LTFLIB "${cmd}查询,要求存在${true_str}" "False"
	
		eval ${cmd} | grep -Ev "${true_str}" | grep "${false_str}"
	        CommRetParse_LTFLIB "${cmd}查询,不存在'${true_str}'以外的值" "False" "yes"
	else
		OutputRet_LTFLIB ${TPASS}
                TestRetParse_LTFLIB "不对 ${file_conf}文件中${flag_str}字段做限制" "False"
	fi

}


#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
